//自己
class Solution {
public:
    int maxArea(vector<int>& height) 
    {
        size_t size = height.size();
        int left=0, right=size-1;
        vector<int> v1;
        v1.reserve(size/2);//预开辟
        while (left != right)
        {
            if (height[left] < height[right])
            {
                //算出体积放入v1
                v1.push_back(height[left] * (right-left));
                ++left;
            }
            else //height[left] >= height[right]
            {
                v1.push_back(height[right] * (right-left));
                --right;
            }
        }
        int max = v1[0];
        for (int e : v1)
        {
            if (e > max)
                max = e;
        }
        return max;
    }
};

//答案
class Solution {
public:
    int maxArea(vector<int>& height) {
        int left = 0, right = height.size() - 1, ret = 0;//0一定比V小的
        while (left < right)//比 left != right更好, 如果出错可能会跳过!=的判断条件, 但left < right不会
        {
            int v = min(height[left], height[right]) * (right-left);//体积
            //cout << v << ' ';cout << left << ' ' << right << endl;//打印找错
            ret = max(ret, v);    //ret = ret > v ? ret : v;//获得之前最大和当前体积的更大值
            //移动指针
            if (height[left] < height[right]) left++;
            else right--;
        }
        return ret;
    }
};